import traceback
import sys
import re

class Main:
	def execute(self, gate):
		p = gate.writen
		classname, exception, trace = sys.exc_info()
		trace = traceback.extract_tb(trace)
		print 'asdasdasdasdasdasdasd'
		p('''		<style type="text/css">
			.__we {
				font-size: 12px;
				font-family: Monospace, Courier New;
				margin: 0px auto;
				border: 1px solid #AAAAAA;
				border-spacing: 0px;
				border-radius: 2px 2px 0 0;
			}
			.__we tbody {
				display: block;
				border: 1px solid #CCCCCC;
				margin: 1px;
				padding: 0;
				border-radius: 2px 2px 0 0;
			}
			.__we td {
				font-size: 12px;
				padding: 0px;
				color: #333333;
			}
			.__we tr.head td {
				background: #555555;
				color: #FFFFFF;
			}
			.__we tr.odd td {
				background: #F7F7F7;
			}
			.__we tr.even td {
				background: #FFFFFF;
			}
			.__we tr.head td, .__we tr.odd td, .__we tr.even td {
				padding: 3px 10px;
			}
			.__we div.exc {
				font-size: 14px;
				background: #990000;
				color: #FFFFFF;
				padding: 10px;
			}
		</style>''')
		p('<table class="__we" width="60%"><tbody>')
		p('<tr><td colspan="10"><div class="exc"><b>%s</b>: %s</div></td></tr>' % (classname.__name__, exception))
		p('<tr class="head"><td width="%s%%">%s</td><td width="%s%%">%s</td><td width="%s%%">%s</td><td width="%s%%">%s</td><td width="%s%%">%s</td></tr>' % (1, 'Depth', 1, 'File', 1, 'Line', 1, 'Method', 100, 'Line'))
		i = 0
		for line in trace:
			line = [re.sub(r'/([a-zA-Z0-9\._-]+)\.([a-zA-Z0-9_-]+)', r'/<b>\1</b>.\2', line[0]), line[1], line[2], line[3]]
			if i % 2 == 0:
				parity = 'even'
			else:
				parity = 'odd'
			p('<tr class="%s"><td>%s</td><td><nobr>%s</nobr></td><td>:%s</td><td><nobr>%s</nobr></td><td>%s</td></tr>' % tuple([parity] + [i - len(trace)] + line))
			i += 1
		p('</tbody></table>')
		print traceback.format_exc()
		return True
